<?php
/**
*@package DDataFormat.cls.php
*@copyright Copyright (c) 2012-2014 Tuniu.com
*@author huxiaomin 2012  下午04:02:38
*@version 1.0
*/

class DDataFormat{

        static public $datatype = array('INT' => 'number_format',
                                  'VARCHAR' => 'mysql_real_escape_string',
                                  'TEXT' => 'mysql_real_escape_string',
                                  'DATE' => 'mysql_real_escape_string',
         							//numeric
                                  'TINYINT' => 'number_format',
                                  'SMALLINT' => 'number_format',
                                  'MEDIUMINT' => 'number_format',
                                  'BIGINT' => 'number_format',
                                  'DECIMAL'=>'number_format',
                                  'FLOAT' => 'number_format',
                                  'DOUBLE' => 'number_format',
                                  'REAL'=> 'number_format',
                                  'BIT' => 'number_format',
                                  'BOOL' => 'number_format',
                                  'SERIAL'=> 'number_format',
        							//date and time
                                  'DATE'=> 'mysql_real_escape_string',
                                  'DATETIME'=> 'mysql_real_escape_string',
                                  'TIMESTAMP'=>'intval',
                                  'TIME' => 'mysql_real_escape_string',
                                  'YEAR'=>'mysql_real_escape_string',
        							//string
                                  'CHAR'=> 'mysql_real_escape_string',
                                  'VARCHAR'=> 'mysql_real_escape_string',
                                  'TINYTEXT'=> 'mysql_real_escape_string',
                                  'TEXT'=> 'mysql_real_escape_string',
                                  'MEDIUMTEXT'=> 'mysql_real_escape_string',
                                  'LONGTEXT'=> 'mysql_real_escape_string',
                                  'BINARY'=> 'mysql_real_escape_string',
                                  'VARBINARY'=> 'mysql_real_escape_string',
                                  'TINYBLOB'=> 'mysql_real_escape_string',
                                  'MEDIUMBLOB'=> 'mysql_real_escape_string',
                                  'BLOB'=> 'mysql_real_escape_string',
                                  'LONGBLOB'=> 'mysql_real_escape_string',
                                  'ENUM'=> 'mysql_real_escape_string',
                                  'SET'=> 'mysql_real_escape_string',
       								 //spatial
                                  'GEOMETRY'=> 'mysql_real_escape_string',
                                  'POINT'=> 'mysql_real_escape_string',
                                  'LINESTRING'=> 'mysql_real_escape_string',
                                  'POLYGON'=> 'mysql_real_escape_string',
                                  'MULTIPOINT'=> 'mysql_real_escape_string',
                                  'MULTILINESTRING'=> 'mysql_real_escape_string',
                                  'MULTIPOLYGON'=> 'mysql_real_escape_string',
                                  'GEOMETRYCOLLECTION'=> 'mysql_real_escape_string',
                                    );
                                    
          static  function getNumber ($number,$type){
          	$func = self::$datatype[strtoupper($type)];
          	if ($func == 'number_format'){
          		return number_format($number,8,'.','');
          	}else {
          		return '\''.mysql_real_escape_string($number).'\'';
          	}	
          }

          static function getValue($number,$type){
            $func = self::$datatype[strtoupper($type)];
            if ($func == 'number_format'){
                return number_format($number,8,'.','');
            }else {
                return mysql_real_escape_string($number);
            }
          }
        
}